Dynomotion

Group: DynoMotion Message: 10209 From: philloder Date: 9/26/2014
Subject: PLC control of positions

I am wanting to control my kflop from a plc. This is similar to a part picker application with the following positions. 

Home position All axis to Zero, Z retracts first!

Eject position "Z to Zero, Y to Zero, X unchanged"

6 rows for Y positions

65 columns for x positions.

Tom showed me some code for a discreet input to move to 1 position. Is it possible to communicate a value to the kflop with serial comm, or do I need to build a table based on binary input value using 7 inputs for x position  and 3 for y. or 9 inputs to give me a possible 511 input values to load the table position variables.


Group: DynoMotion Message: 10212 From: Tom Kerekes Date: 9/26/2014
Subject: Re: PLC control of positions
KFLOP has a UART that can send/receive serial data.  See:


Or your binary IO approach seems reasonable.  You might consider having an approach where you have something like a "7-bit data bus" and several command strobes such as: StrobeRow, StrobeCol, StrobeMiscCommand.

The StrobeMiscCommand would allow sending up to 128 different command codes to KFLOP such as" "Move", "RetractZ", "Home", and whatnot.

HTH
Regards
TK




From: "philloder@... [DynoMotion]" <DynoMotion@yahoogroups.com>
To: DynoMotion@yahoogroups.com
Sent: Friday, September 26, 2014 1:45 PM
Subject: [DynoMotion] PLC control of positions

 
I am wanting to control my kflop from a plc. This is similar to a part picker application with the following positions. 
Home position All axis to Zero, Z retracts first!
Eject position "Z to Zero, Y to Zero, X unchanged"
6 rows for Y positions
65 columns for x positions.
Tom showed me some code for a discreet input to move to 1 position. Is it possible to communicate a value to the kflop with serial comm, or do I need to build a table based on binary input value using 7 inputs for x position  and 3 for y. or 9 inputs to give me a possible 511 input values to load the table position variables.



Group: DynoMotion Message: 10215 From: phil loder Date: 9/26/2014
Subject: Re: PLC control of positions
Tom,
Thanks for the reply and the info on adapters for TTL level signal converter.
I have a kflop, kstep, and a Kconnect card for my system. Is there anyplace to hook to for communication with my configuration?
regards,
Phil


On Friday, September 26, 2014 5:52 PM, "Tom Kerekes tk@... [DynoMotion]" <DynoMotion@yahoogroups.com> wrote:


 
KFLOP has a UART that can send/receive serial data.  See:


Or your binary IO approach seems reasonable.  You might consider having an approach where you have something like a "7-bit data bus" and several command strobes such as: StrobeRow, StrobeCol, StrobeMiscCommand.

The StrobeMiscCommand would allow sending up to 128 different command codes to KFLOP such as" "Move", "RetractZ", "Home", and whatnot.

HTH
Regards
TK




From: "philloder@... [DynoMotion]" <DynoMotion@yahoogroups.com>
To: DynoMotion@yahoogroups.com
Sent: Friday, September 26, 2014 1:45 PM
Subject: [DynoMotion] PLC control of positions

 
I am wanting to control my kflop from a plc. This is similar to a part picker application with the following positions. 
Home position All axis to Zero, Z retracts first!
Eject position "Z to Zero, Y to Zero, X unchanged"
6 rows for Y positions
65 columns for x positions.
Tom showed me some code for a discreet input to move to 1 position. Is it possible to communicate a value to the kflop with serial comm, or do I need to build a table based on binary input value using 7 inputs for x position  and 3 for y. or 9 inputs to give me a possible 511 input values to load the table position variables.





Group: DynoMotion Message: 10217 From: Tom Kerekes Date: 9/27/2014
Subject: Re: PLC control of positions
Hi Phil,

Sorry I forgot you have a KSTEP that normally uses all of KFLOP JP7 and makes it difficult to use KFLOP's Serial UART on JP7.

The only things I can think of are:

#1 break out wires IO44 Pin6 and IO45 Pin7 from KFLOP JP7 to make use of the UART.  These two signals will then be missing going to KSTEP.  IO44 is normally configured as a PWM signal to make use of KSTEP's Analog Output.  If you don't need the Analog output then you can leave this signal open.  If the Analog signal is required then one of KSTEP's other PWM outputs could be wired to this pin.  IO45 is normally used to control the Enable Signal to KSTEP.  The Enable input on KSTEP J6 (or the original JP36 Pin7) can be connected to another 3.3V output or wired to 3.3V directly to Enable KSTEP. 

#2 Use KFLOP JP5 to connect Step/Dir signals to KSTEP to completely free up KFLOP JP7.  In this case +5V, GND, and Enable will need to be wired externally to KSTEP J6.  The Opto IO (KSTEP JP33) will not be available.

HTH
Regards
TK


Group: DynoMotion Message: 10241 From: phil loder Date: 10/3/2014
Subject: Re: PLC control of positions
Tom,
I have decided to go with the inputs on the konnect 0-8 for my position word value of 0-511 and use 9 to start the motion. 11 is the eject command and 11-14 reserved for control input functions at a later date and 15 for a home routine. 
First the inputs 0-8 wont be debounced as nothing happens till input 9 "bit 1033" is debounced and true.
x positions are equal .5" increments from 1 to 66  columns starting at 2". y position will be a constant value between 6 rows starting at 4" and decreasing .5" for each row and Zero. z position is either zero or -1.0".
if position value >1 and <66 then x=2+(position * .5)  y=4 and when move is complete z=-1.0 and output 0 bit "Virtual 48" comes on indication motion complete like the InputTriggersMotion.c program you sent.
all axis motion will hold untill the plc issues a "Eject" command on input 11 " bit 1035" that retracts z to zero and then y to zero.
When complete it turns on output 1 bit "Virtual 49" showing machine is in eject position.
it will remain there for around a second and then receive a new position command.

the rows below 1 are offset .030" positive per row to form a parallelogram so position 66 x=2.030" starting position y =3.5"
132 x=2.060 y=3.0"  and so on. 

Position "0" zero is just that and all 3 axis return to home with "Z" retracting first. 

I have gotten the InputTriggersMotion.c Running as thread 2 and works fine as it is. 
Could you get me started with a modified version InputWordTriggersMotion.c that functions as above.
regards,
Phil Loder



On Saturday, September 27, 2014 10:35 AM, "Tom Kerekes tk@... [DynoMotion]" <DynoMotion@yahoogroups.com> wrote:


 
Hi Phil,

Sorry I forgot you have a KSTEP that normally uses all of KFLOP JP7 and makes it difficult to use KFLOP's Serial UART on JP7.

The only things I can think of are:

#1 break out wires IO44 Pin6 and IO45 Pin7 from KFLOP JP7 to make use of the UART.  These two signals will then be missing going to KSTEP.  IO44 is normally configured as a PWM signal to make use of KSTEP's Analog Output.  If you don't need the Analog output then you can leave this signal open.  If the Analog signal is required then one of KSTEP's other PWM outputs could be wired to this pin.  IO45 is normally used to control the Enable Signal to KSTEP.  The Enable input on KSTEP J6 (or the original JP36 Pin7) can be connected to another 3.3V output or wired to 3.3V directly to Enable KSTEP. 

#2 Use KFLOP JP5 to connect Step/Dir signals to KSTEP to completely free up KFLOP JP7.  In this case +5V, GND, and Enable will need to be wired externally to KSTEP J6.  The Opto IO (KSTEP JP33) will not be available.

HTH
Regards
TK


Group: DynoMotion Message: 10243 From: Tom Kerekes Date: 10/4/2014
Subject: Re: PLC control of positions
Attachments :
    Hi Phil,

    Maybe something like the attached?

    Regards
    TK

    Group: DynoMotion Message: 10244 From: philloder Date: 10/5/2014
    Subject: Re: PLC control of positions
    Tom,
    Thanks for the Help. At first I thought that none of the math worked for the word value and positions. 
    Then I realized that in building the 9 bit word you were using the first word bit as the highest significant value not the lowest.
    Is there a easy correction for the word build or do I need to rewire to make my outputs match your math from the inputs?
    thanks,
    Phil
    Group: DynoMotion Message: 10245 From: Tom Kerekes Date: 10/5/2014
    Subject: Re: PLC control of positions
    Hi Phil,

    Try changing to read the bits in reverse order.  Instead of incrementing i from 0 to 8, decrement it from 8 downto 0.

    Change:

    for (i=0; i<9; i++)

    to

    for (i=8; i>=0; i--)

    Regards
    TK

    Group: DynoMotion Message: 10246 From: phil loder Date: 10/5/2014
    Subject: Re: PLC control of positions
    Tom,
    Worked like a charm !!!
    Thanks,
    Phil


    On Sunday, October 5, 2014 4:30 PM, "Tom Kerekes tk@... [DynoMotion]" <DynoMotion@yahoogroups.com> wrote:


     
    Hi Phil,

    Try changing to read the bits in reverse order.  Instead of incrementing i from 0 to 8, decrement it from 8 downto 0.

    Change:

    for (i=0; i<9; i++)

    to

    for (i=8; i>=0; i--)

    Regards
    TK

    Group: DynoMotion Message: 10328 From: philloder Date: 10/14/2014
    Subject: Re: PLC control of positions
    Tom,
    I had to modify the program you set up for me. 
    InputWordTriggersMotion.C as I needed to start at the bottom left and work up not the top left and work down.
    I actually made the changed to the code along with some spacing offset adjustments. That all works fine except that position 1 is 1 inch to the right "2 Columns"  of all the rest of the row starting positions.

    Also I have tried to modify the program to include the feed hold on input 1036 and nothing stops 

    input 1037 is supposed to run thread 3 which runs at startup to home all 3 axis and if I run 3 from the kmotion C-Program screen it works correctly. I thought I had followed your examples but am missing something.

    I am going to include a jog function but it is probably not working due to what ever I have missed on the entries above.
    My mods are below.

    #include "KMotionDef.h"

    #define XAXIS 0 // define an Axis channel Number to use
    #define YAXIS 1 // define an Axis channel Number to use
    #define ZAXIS 2 // define an Axis channel Number to use

    #define STEP1_COMPLETE 48
    #define STEP2_COMPLETE 49


    #define FIRST_WORD_BIT 1024

    #define TRIGGER_STEP1 1033 // MOVE TO POSITION WORD
    #define TRIGGER_STEP2 1034 // MOVE TO EJECT

    #define FEED_HOLD 1036  // feed hold all axis
    #define ZERO_ALL 1037  // ZERO ALL AXIS RUNNING THREAD 3

    #define JOG_X_POS 1050 // JOG X POSITIVE
    #define JOG_X_NEG 1051 // JOG X NEGATIVE
    #define JOG_Y_POS 1052 // JOG Y POSITIVE
    #define JOG_Y_NEG 1053 // JOG Y NEGATIVE
    #define JOG_X_POS 1054 // JOG Z POSITIVE
    #define JOG_Z_NEG 1055 // JOG Z NEGATIVE

    #define COL ((word+1)%67) // row is word modulo 66 but 0 is special
    #define ROW ((word+1)/67) // col is word/66 but 0 is special 

    #define STEPS_PER_INCH 16271.18644

    //#define XPOS(word) ((1.0 + COL * 0.5 + ROW * 0.030)*STEPS_PER_INCH)
    #define XPOS(word) ((0.00 + COL * 0.5 + ROW * 0.10)*STEPS_PER_INCH)
    #define YPOS(word) ((0.60 + ROW * 0.7)*STEPS_PER_INCH)
    // #define YPOS(word) ((4.0 + ROW * -0.5)*STEPS_PER_INCH)
    #define ZPOS ((-1.00)*STEPS_PER_INCH)

    // state variables for switch debouncing
    int t1last=0,t1lastsolid=-1,t1count=0;
    int t2last=0,t2lastsolid=-1,t2count=0;
    int t3last=0,t3lastsolid=-1,t3count=0;
    int t4last=0,t4lastsolid=-1,t4count=0;


    main()
    {
    int i,word;
    KStepPresent=TRUE;      // enable KSTEP input multiplexing

    ClearBit(STEP1_COMPLETE);
    ClearBit(STEP2_COMPLETE);
    for (;;) // loop forever
    {
    WaitNextTimeSlice();
    // Handle Step1 Input
    if  (Debounce(ReadBit(TRIGGER_STEP1),&t1count,&t1last,&t1lastsolid) == 1)
    {
    ClearBit(STEP1_COMPLETE);
    ClearBit(STEP2_COMPLETE);

    // build the 9 bit word
    word=0;
    for (i=8;i>=0;i--) word = word*2 + ReadBit(FIRST_WORD_BIT+i);
    if (word==0)  // position 0 is special
    {
    Move(ZAXIS,0.0); // retract z
    while (!CheckDone(ZAXIS)) ; // wait for Z to finish 

    Move(XAXIS,0.0);  // move xy home at the same time
    Move(YAXIS,0.0);
    while (!CheckDone(XAXIS) || !CheckDone(YAXIS)) ; // wait for XY to finish 
    }
    else
    {
    Move(XAXIS,XPOS(word));  // move xy at the same time
    Move(YAXIS,YPOS(word));
    while (!CheckDone(XAXIS) || !CheckDone(YAXIS)) ; // wait for XY to finish 

    Move(ZAXIS,ZPOS); // now Z down
    while (!CheckDone(ZAXIS)) ; // wait for Z to finish 
    }
    SetBit(STEP1_COMPLETE);  // signal to PLC Complete
    }

    // Handle Step2 Input
    if  (Debounce(ReadBit(TRIGGER_STEP2),&t2count,&t2last,&t2lastsolid) == 1)
    {
    ClearBit(STEP1_COMPLETE);
    ClearBit(STEP2_COMPLETE);

    Move(ZAXIS,0.00); // retract z
    while (!CheckDone(ZAXIS)) ; // wait for Z to finish 

    Move(YAXIS,0.0); // retract y
    while (!CheckDone(YAXIS)) ; // wait for Y to finish 

    SetBit(STEP2_COMPLETE);  // signal to PLC Complete
    }
    // Handle ZERO Input
    if  (Debounce(ReadBit(ZERO_ALL),&t3count,&t3last,&t3lastsolid) == 1)
    {
    void StartThread(3);
    }
    // Handle FEED_HOLD Input
    if  (Debounce(ReadBit(FEED_HOLD),&t4count,&t4last,&t4lastsolid) == 1)
    {
    StopCoordinatedMotion();
    }
    else
    {
    ResumeCoordinatedMotion();
    }
    }
    }





    // Debounce a bit
    //
    // return 1 one time when first debounced high 
    // return 0 one time when first debounced low 
    // return -1 otherwise 
    #define DBTIME 300

    int Debounce(int n, int *cnt, int *last, int *lastsolid)
    {
    int v = -1;
    if (n == *last)  // same as last time?
    {
    if (*cnt == DBTIME-1)
    {
    if (n != *lastsolid)
    {
    v = *lastsolid = n;  // return debounced value
    }
    }
    if (*cnt < DBTIME) (*cnt)++;
    }
    else
    {
    *cnt = 0;  // reset count
    }
    *last = n;
    return v;
    }


    Group: DynoMotion Message: 10329 From: Tom Kerekes Date: 10/15/2014
    Subject: Re: PLC control of positions
    Attachments :
      Hi Phill,

      I think:

      #define COL ((word+1)%67) // row is word modulo 66 but 0 is special
      #define ROW ((word+1)/67) // col is word/66 but 0 is special 

      Should really be:

      #define COL ((word-1)%67) // row is word modulo 66 but 0 is special
      #define ROW ((word-1)/67) // col is word/66 but 0 is special 

      Regarding feedhold the code stops looping when issuing moves and waits for the moves to complete.  This results in only checking for feedhold when not doing a cycle.  I made the check for feedhold into a function and call it also while waiting for moves to complete withing the cycles.

      I tried to add in some code to debounce your Jog switches and command Jogs.

      Regarding starting Thread#3 to do homing.  You would need to Flash that program to be in memory in order to start it.  The "save/compile/download/run" button in KMotion does a download to memory.  You can't really do that from KFLOP.  It is probably better to just add that Home function into this same porogam and Thread. Then you can just call it there rather than trying to run it as a separate program and Thread.

      See the attached.

      HTH
      Regards
      TK


      From: "philloder@... [DynoMotion]" <DynoMotion@yahoogroups.com>
      To: DynoMotion@yahoogroups.com
      Sent: Tuesday, October 14, 2014 2:05 PM
      Subject: Re: [DynoMotion] PLC control of positions

       
      Tom,
      I had to modify the program you set up for me. 
      InputWordTriggersMotion.C as I needed to start at the bottom left and work up not the top left and work down.
      I actually made the changed to the code along with some spacing offset adjustments. That all works fine except that position 1 is 1 inch to the right "2 Columns"  of all the rest of the row starting positions.

      Also I have tried to modify the program to include the feed hold on input 1036 and nothing stops 

      input 1037 is supposed to run thread 3 which runs at startup to home all 3 axis and if I run 3 from the kmotion C-Program screen it works correctly. I thought I had followed your examples but am missing something.

      I am going to include a jog function but it is probably not working due to what ever I have missed on the entries above.
      My mods are below.

      #include "KMotionDef.h"

      #define XAXIS 0 // define an Axis channel Number to use
      #define YAXIS 1 // define an Axis channel Number to use
      #define ZAXIS 2 // define an Axis channel Number to use

      #define STEP1_COMPLETE 48
      #define STEP2_COMPLETE 49


      #define FIRST_WORD_BIT 1024

      #define TRIGGER_STEP1 1033 // MOVE TO POSITION WORD
      #define TRIGGER_STEP2 1034 // MOVE TO EJECT

      #define FEED_HOLD 1036  // feed hold all axis
      #define ZERO_ALL 1037  // ZERO ALL AXIS RUNNING THREAD 3

      #define JOG_X_POS 1050 // JOG X POSITIVE
      #define JOG_X_NEG 1051 // JOG X NEGATIVE
      #define JOG_Y_POS 1052 // JOG Y POSITIVE
      #define JOG_Y_NEG 1053 // JOG Y NEGATIVE
      #define JOG_X_POS 1054 // JOG Z POSITIVE
      #define JOG_Z_NEG 1055 // JOG Z NEGATIVE

      #define COL ((word+1)%67) // row is word modulo 66 but 0 is special
      #define ROW ((word+1)/67) // col is word/66 but 0 is special 

      #define STEPS_PER_INCH 16271.18644

      //#define XPOS(word) ((1.0 + COL * 0.5 + ROW * 0.030)*STEPS_PER_INCH)
      #define XPOS(word) ((0.00 + COL * 0.5 + ROW * 0.10)*STEPS_PER_INCH)
      #define YPOS(word) ((0.60 + ROW * 0.7)*STEPS_PER_INCH)
      // #define YPOS(word) ((4.0 + ROW * -0.5)*STEPS_PER_INCH)
      #define ZPOS ((-1.00)*STEPS_PER_INCH)

      // state variables for switch debouncing
      int t1last=0,t1lastsolid=-1,t1count=0;
      int t2last=0,t2lastsolid=-1,t2count=0;
      int t3last=0,t3lastsolid=-1,t3count=0;
      int t4last=0,t4lastsolid=-1,t4count=0;


      main()
      {
      int i,word;
      KStepPresent=TRUE;      // enable KSTEP input multiplexing

      ClearBit(STEP1_COMPLETE);
      ClearBit(STEP2_COMPLETE);
      for (;;) // loop forever
      {
      WaitNextTimeSlice();
      // Handle Step1 Input
      if  (Debounce(ReadBit(TRIGGER_STEP1),&t1count,&t1last,&t1lastsolid) == 1)
      {
      ClearBit(STEP1_COMPLETE);
      ClearBit(STEP2_COMPLETE);

      // build the 9 bit word
      word=0;
      for (i=8;i>=0;i--) word = word*2 + ReadBit(FIRST_WORD_BIT+i);
      if (word==0)  // position 0 is special
      {
      Move(ZAXIS,0.0); // retract z
      while (!CheckDone(ZAXIS)) ; // wait for Z to finish 

      Move(XAXIS,0.0);  // move xy home at the same time
      Move(YAXIS,0.0);
      while (!CheckDone(XAXIS) || !CheckDone(YAXIS)) ; // wait for XY to finish 
      }
      else
      {
      Move(XAXIS,XPOS(word));  // move xy at the same time
      Move(YAXIS,YPOS(word));
      while (!CheckDone(XAXIS) || !CheckDone(YAXIS)) ; // wait for XY to finish 

      Move(ZAXIS,ZPOS); // now Z down
      while (!CheckDone(ZAXIS)) ; // wait for Z to finish 
      }
      SetBit(STEP1_COMPLETE);  // signal to PLC Complete
      }

      // Handle Step2 Input
      if  (Debounce(ReadBit(TRIGGER_STEP2),&t2count,&t2last,&t2lastsolid) == 1)
      {
      ClearBit(STEP1_COMPLETE);
      ClearBit(STEP2_COMPLETE);

      Move(ZAXIS,0.00); // retract z
      while (!CheckDone(ZAXIS)) ; // wait for Z to finish 

      Move(YAXIS,0.0); // retract y
      while (!CheckDone(YAXIS)) ; // wait for Y to finish 

      SetBit(STEP2_COMPLETE);  // signal to PLC Complete
      }
      // Handle ZERO Input
      if  (Debounce(ReadBit(ZERO_ALL),&t3count,&t3last,&t3lastsolid) == 1)
      {
      void StartThread(3);
      }
      // Handle FEED_HOLD Input
      if  (Debounce(ReadBit(FEED_HOLD),&t4count,&t4last,&t4lastsolid) == 1)
      {
      StopCoordinatedMotion();
      }
      else
      {
      ResumeCoordinatedMotion();
      }
      }
      }





      // Debounce a bit
      //
      // return 1 one time when first debounced high 
      // return 0 one time when first debounced low 
      // return -1 otherwise 
      #define DBTIME 300

      int Debounce(int n, int *cnt, int *last, int *lastsolid)
      {
      int v = -1;
      if (n == *last)  // same as last time?
      {
      if (*cnt == DBTIME-1)
      {
      if (n != *lastsolid)
      {
      v = *lastsolid = n;  // return debounced value
      }
      }
      if (*cnt < DBTIME) (*cnt)++;
      }
      else
      {
      *cnt = 0;  // reset count
      }
      *last = n;
      return v;
      }




      Group: DynoMotion Message: 10331 From: phil loder Date: 10/16/2014
      Subject: Re: PLC control of positions
      Tom,
      I attached all the c programs running and flashed into memory
      thread 1    AYC_Kstep3Axis.c
      thread2   InputWordTriggersMotion_WithHome.c
      thread3   AYCSimpleHome3Axis.c

      Thread 3 runs on powerup to home all 3 axis
      I added code from it to thread2 to home when "ZERO_ALL" bit is true and it works fine.
      I checked the changes you made to the code for defining the rows and columns and they work correctly now.
      the feedhold only works when jogging a axis.
      Jogging does not stop when button is released, it will also continue to run when a limit switch is made.
      When we have corrected the feedhold issue, I would like to have bit 50 turn on when the feedhold button is on and/or when feedhold in enabled by running into the limits. also toggling feedhold should allow movement away from the limit stopping motion.



      On Wednesday, October 15, 2014 8:21 PM, "Tom Kerekes tk@... [DynoMotion]" <DynoMotion@yahoogroups.com> wrote:


       
      Hi Phill,

      I think:

      #define COL ((word+1)%67) // row is word modulo 66 but 0 is special
      #define ROW ((word+1)/67) // col is word/66 but 0 is special 

      Should really be:

      #define COL ((word-1)%67) // row is word modulo 66 but 0 is special
      #define ROW ((word-1)/67) // col is word/66 but 0 is special 

      Regarding feedhold the code stops looping when issuing moves and waits for the moves to complete.  This results in only checking for feedhold when not doing a cycle.  I made the check for feedhold into a function and call it also while waiting for moves to complete withing the cycles.

      I tried to add in some code to debounce your Jog switches and command Jogs.

      Regarding starting Thread#3 to do homing.  You would need to Flash that program to be in memory in order to start it.  The "save/compile/download/run" button in KMotion does a download to memory.  You can't really do that from KFLOP.  It is probably better to just add that Home function into this same porogam and Thread. Then you can just call it there rather than trying to run it as a separate program and Thread.

      See the attached.

      HTH
      Regards
      TK


      From: "philloder@... [DynoMotion]" <DynoMotion@yahoogroups.com>
      To: DynoMotion@yahoogroups.com
      Sent: Tuesday, October 14, 2014 2:05 PM
      Subject: Re: [DynoMotion] PLC control of positions

       
      Tom,
      I had to modify the program you set up for me. 
      InputWordTriggersMotion.C as I needed to start at the bottom left and work up not the top left and work down.
      I actually made the changed to the code along with some spacing offset adjustments. That all works fine except that position 1 is 1 inch to the right "2 Columns"  of all the rest of the row starting positions.

      Also I have tried to modify the program to include the feed hold on input 1036 and nothing stops 

      input 1037 is supposed to run thread 3 which runs at startup to home all 3 axis and if I run 3 from the kmotion C-Program screen it works correctly. I thought I had followed your examples but am missing something.

      I am going to include a jog function but it is probably not working due to what ever I have missed on the entries above.
      My mods are below.

      #include "KMotionDef.h"

      #define XAXIS 0 // define an Axis channel Number to use
      #define YAXIS 1 // define an Axis channel Number to use
      #define ZAXIS 2 // define an Axis channel Number to use

      #define STEP1_COMPLETE 48
      #define STEP2_COMPLETE 49


      #define FIRST_WORD_BIT 1024

      #define TRIGGER_STEP1 1033 // MOVE TO POSITION WORD
      #define TRIGGER_STEP2 1034 // MOVE TO EJECT

      #define FEED_HOLD 1036  // feed hold all axis
      #define ZERO_ALL 1037  // ZERO ALL AXIS RUNNING THREAD 3

      #define JOG_X_POS 1050 // JOG X POSITIVE
      #define JOG_X_NEG 1051 // JOG X NEGATIVE
      #define JOG_Y_POS 1052 // JOG Y POSITIVE
      #define JOG_Y_NEG 1053 // JOG Y NEGATIVE
      #define JOG_X_POS 1054 // JOG Z POSITIVE
      #define JOG_Z_NEG 1055 // JOG Z NEGATIVE

      #define COL ((word+1)%67) // row is word modulo 66 but 0 is special
      #define ROW ((word+1)/67) // col is word/66 but 0 is special 

      #define STEPS_PER_INCH 16271.18644

      //#define XPOS(word) ((1.0 + COL * 0.5 + ROW * 0.030)*STEPS_PER_INCH)
      #define XPOS(word) ((0.00 + COL * 0.5 + ROW * 0.10)*STEPS_PER_INCH)
      #define YPOS(word) ((0.60 + ROW * 0.7)*STEPS_PER_INCH)
      // #define YPOS(word) ((4.0 + ROW * -0.5)*STEPS_PER_INCH)
      #define ZPOS ((-1.00)*STEPS_PER_INCH)

      // state variables for switch debouncing
      int t1last=0,t1lastsolid=-1,t1count=0;
      int t2last=0,t2lastsolid=-1,t2count=0;
      int t3last=0,t3lastsolid=-1,t3count=0;
      int t4last=0,t4lastsolid=-1,t4count=0;


      main()
      {
      int i,word;
      KStepPresent=TRUE;      // enable KSTEP input multiplexing

      ClearBit(STEP1_COMPLETE);
      ClearBit(STEP2_COMPLETE);
      for (;;) // loop forever
      {
      WaitNextTimeSlice();
      // Handle Step1 Input
      if  (Debounce(ReadBit(TRIGGER_STEP1),&t1count,&t1last,&t1lastsolid) == 1)
      {
      ClearBit(STEP1_COMPLETE);
      ClearBit(STEP2_COMPLETE);

      // build the 9 bit word
      word=0;
      for (i=8;i>=0;i--) word = word*2 + ReadBit(FIRST_WORD_BIT+i);
      if (word==0)  // position 0 is special
      {
      Move(ZAXIS,0.0); // retract z
      while (!CheckDone(ZAXIS)) ; // wait for Z to finish 

      Move(XAXIS,0.0);  // move xy home at the same time
      Move(YAXIS,0.0);
      while (!CheckDone(XAXIS) || !CheckDone(YAXIS)) ; // wait for XY to finish 
      }
      else
      {
      Move(XAXIS,XPOS(word));  // move xy at the same time
      Move(YAXIS,YPOS(word));
      while (!CheckDone(XAXIS) || !CheckDone(YAXIS)) ; // wait for XY to finish 

      Move(ZAXIS,ZPOS); // now Z down
      while (!CheckDone(ZAXIS)) ; // wait for Z to finish 
      }
      SetBit(STEP1_COMPLETE);  // signal to PLC Complete
      }

      // Handle Step2 Input
      if  (Debounce(ReadBit(TRIGGER_STEP2),&t2count,&t2last,&t2lastsolid) == 1)
      {
      ClearBit(STEP1_COMPLETE);
      ClearBit(STEP2_COMPLETE);

      Move(ZAXIS,0.00); // retract z
      while (!CheckDone(ZAXIS)) ; // wait for Z to finish 

      Move(YAXIS,0.0); // retract y
      while (!CheckDone(YAXIS)) ; // wait for Y to finish 

      SetBit(STEP2_COMPLETE);  // signal to PLC Complete
      }
      // Handle ZERO Input
      if  (Debounce(ReadBit(ZERO_ALL),&t3count,&t3last,&t3lastsolid) == 1)
      {
      void StartThread(3);
      }
      // Handle FEED_HOLD Input
      if  (Debounce(ReadBit(FEED_HOLD),&t4count,&t4last,&t4lastsolid) == 1)
      {
      StopCoordinatedMotion();
      }
      else
      {
      ResumeCoordinatedMotion();
      }
      }
      }





      // Debounce a bit
      //
      // return 1 one time when first debounced high 
      // return 0 one time when first debounced low 
      // return -1 otherwise 
      #define DBTIME 300

      int Debounce(int n, int *cnt, int *last, int *lastsolid)
      {
      int v = -1;
      if (n == *last)  // same as last time?
      {
      if (*cnt == DBTIME-1)
      {
      if (n != *lastsolid)
      {
      v = *lastsolid = n;  // return debounced value
      }
      }
      if (*cnt < DBTIME) (*cnt)++;
      }
      else
      {
      *cnt = 0;  // reset count
      }
      *last = n;
      return v;
      }






        @@attachment@@
      Group: DynoMotion Message: 10332 From: Tom Kerekes Date: 10/16/2014
      Subject: Re: PLC control of positions [3 Attachments]
      Attachments :
        Hi Phil,

        I fixed a bug with the Jog buttons.  I can't see why Feed hold wouldn't work with the Trigger cycles.  It will not work while homing because we didn't put in the checks.  Is that what you observe?

        Regards
        TK

        Group: DynoMotion Message: 10333 From: phil loder Date: 10/16/2014
        Subject: Re: PLC control of positions
        Tom,
        I just tested the Jog command and it stops jogging when the button is released. It will still jog into the limit switches without stopping.
        the feed hold is kind of weird on triggered move. lets say we are at home 0,0,0 and we enter a position of 30. It should go to
        X 14.6" 
        Y 0.6"
        Z -1.0"
        If I toggle feed hold while x is moving it stops x and y from moving then moves z from 0.0 to -1.0".
        I stop the PLC during a feed hold. If I dont stop the PLC the motion will continue untill z extends to -1 and then it stops.


        On Thursday, October 16, 2014 12:08 PM, "Tom Kerekes tk@... [DynoMotion]" <DynoMotion@yahoogroups.com> wrote:


         
        Hi Phil,

        I fixed a bug with the Jog buttons.  I can't see why Feed hold wouldn't work with the Trigger cycles.  It will not work while homing because we didn't put in the checks.  Is that what you observe?

        Regards
        TK

        Group: DynoMotion Message: 10334 From: philloder Date: 10/16/2014
        Subject: Re: PLC control of positions
        i just toggled the feedhold after motion started for step 2 input and it did a complete cycle of z to zero y to zero sent step2_complete. the PLC upon seeing that input sent a trigger_step1 and x went to the next row, y went to its last position and z went to -1.0 and then stopped and sent step1_complete.
        normally I would stop the PLC from sending a new position request when feedhold ==1 but tried this for raw c code testing.
        Group: DynoMotion Message: 10337 From: Tom Kerekes Date: 10/18/2014
        Subject: Re: PLC control of positions
        Attachments :
          Hi Phil,

          I think I fixed two things.  Try the attached.

          Regards
          TK

          Group: DynoMotion Message: 10338 From: phil loder Date: 10/19/2014
          Subject: Re: PLC control of positions
          Tom,
          I tried the mods and My limits are back to working. 
          When I make a limit switch all motion stops and I have to toggle feedhold to resume. 
          When I turn on  the feedhold bit during a triggered move it stops all motion, If motion was stopped before it was complete on a axis the system seems to think that that axis has completed motion and will complete the next axis moves.   x is supposed to go to 20 and feedhold stops it at 10. upon clearing feedhold x stays at 10 instead of finishing its move then z makes its move thinking x,y are in position.Crash!

          I tried to modify the following to show the status of feed_Hold and it works if I toggle the input, but not if a limit switch is made.

          #define FEEDHOLD_IND 50

          void ServiceFeedhold(void)
          {
          int result;
          WaitNextTimeSlice();

          result = Debounce(ReadBit(FEED_HOLD),&t4count,&t4last,&t4lastsolid);

          // Handle FEED_HOLD Input
          if  (result == 1)
          {
          StopCoordinatedMotion();
          SetBit(FEEDHOLD_IND);
          }
          if (result == 0)
          {
          ResumeCoordinatedMotion();
          ClearBit(FEEDHOLD_IND);
          }
          }
          I thought removing my SetBit/ClearBit (FEED_HOLD) and adding the following would work, I was wrong!!! 
          But I am trying to do some on my own. What am I doing wrong in this code?

          // GET STOP STATE AND TURN ON/OFF INDICATOR "FEEDHOLD_IND"

          {
                  GetStopState();

          WaitNextTimeSlice();
          if  (CS0_StoppingState == 4);  // 4=independent motion of all related axes fully  stopped
          {
          SetBit(FEEDHOLD_IND);
          }
          if (CS0_StoppingState == 0);  //0 = not stopping
          {
          ClearBit(FEEDHOLD_IND);
          }
          }


          On Saturday, October 18, 2014 8:49 PM, "Tom Kerekes tk@... [DynoMotion]" <DynoMotion@yahoogroups.com> wrote:


           
          Hi Phil,

          I think I fixed two things.  Try the attached.

          Regards
          TK

          Group: DynoMotion Message: 10339 From: Tom Kerekes Date: 10/19/2014
          Subject: Re: PLC control of positions
          H Phil,

          That seems to reveal a bug in KFLOP resuming from feedhold.  Please try applying this patch:


          To apply this patch you must be using the latest Test Release V 4.33g


          Copy to the DSP_KFLOP Directory and Flash New Version

          Regarding the Feed Hold Indicator - I applaud you writing code!  But the the fuction GetStopState doesn't exist.  You should just be able to test CS0_StoppingState for non zero with:


          if  (CS0_StoppingState == 0);  // 0=no feed hold in progress
          {
              ClearBit(FEEDHOLD_IND);}
          else
          {
              ClearBit(FEEDHOLD_IND);
          }


          Regards
          TK


          From: "phil loder philloder@... [DynoMotion]" <DynoMotion@yahoogroups.com>
          To: "DynoMotion@yahoogroups.com" <DynoMotion@yahoogroups.com>
          Sent: Sunday, October 19, 2014 8:35 AM
          Subject: Re: [DynoMotion] PLC control of positions

           
          Tom,
          I tried the mods and My limits are back to working. 
          When I make a limit switch all motion stops and I have to toggle feedhold to resume. 
          When I turn on  the feedhold bit during a triggered move it stops all motion, If motion was stopped before it was complete on a axis the system seems to think that that axis has completed motion and will complete the next axis moves.   x is supposed to go to 20 and feedhold stops it at 10. upon clearing feedhold x stays at 10 instead of finishing its move then z makes its move thinking x,y are in position.Crash!

          I tried to modify the following to show the status of feed_Hold and it works if I toggle the input, but not if a limit switch is made.

          #define FEEDHOLD_IND 50

          void ServiceFeedhold(void)
          {
          int result;
          WaitNextTimeSlice();

          result = Debounce(ReadBit(FEED_HOLD),&t4count,&t4last,&t4lastsolid);

          // Handle FEED_HOLD Input
          if  (result == 1)
          {
          StopCoordinatedMotion();
          SetBit(FEEDHOLD_IND);
          }
          if (result == 0)
          {
          ResumeCoordinatedMotion();
          ClearBit(FEEDHOLD_IND);
          }
          }
          I thought removing my SetBit/ClearBit (FEED_HOLD) and adding the following would work, I was wrong!!! 
          But I am trying to do some on my own. What am I doing wrong in this code?

          // GET STOP STATE AND TURN ON/OFF INDICATOR "FEEDHOLD_IND"

          {
                  GetStopState();

          WaitNextTimeSlice();
          if  (CS0_StoppingState == 4);  // 4=independent motion of all related axes fully  stopped
          {
          SetBit(FEEDHOLD_IND);
          }
          if (CS0_StoppingState == 0);  //0 = not stopping
          {
          ClearBit(FEEDHOLD_IND);
          }
          }


          On Saturday, October 18, 2014 8:49 PM, "Tom Kerekes tk@... [DynoMotion]" <DynoMotion@yahoogroups.com> wrote:


           
          Hi Phil,

          I think I fixed two things.  Try the attached.

          Regards
          TK


          From: "philloder@... [DynoMotion]" <DynoMotion@yahoogroups.com>
          To: DynoMotion@yahoogroups.com
          Sent: Thursday, October 16, 2014 12:38 PM
          Subject: Re: [DynoMotion] PLC control of positions

           
          i just toggled the feedhold after motion started for step 2 input and it did a complete cycle of z to zero y to zero sent step2_complete. the PLC upon seeing that input sent a trigger_step1 and x went to the next row, y went to its last position and z went to -1.0 and then stopped and sent step1_complete.
          normally I would stop the PLC from sending a new position request when feedhold ==1 but tried this for raw c code testing.






          Group: DynoMotion Message: 10345 From: phil loder Date: 10/20/2014
          Subject: Re: PLC control of positions
          Tom,
          I flashed the update and included the new DSPKFLOP.out and saved the old one with a old extension.
          I reloaded my 2 threads and flashed them to user memory. verified the version in console as KFLOP 4.33h Build 18:42:16 Oct 19 2014
          when testing the stopping of a move with feedhold, it is stopping and continuing correctly when it is a commanded move.
          When I tested the limit switches they did not stop the axis. I had to do the save,compile,download,run and then it worked. Its weird due to the fact that the homing routine is in the same thread and ran fine. it also uses the near limit switched that I used for testing the feedhold on limits. Both thread 1,2 are checked to run on startup. 
          When the "Y" limit is made during a jog and it does stop, as soon as you toggle feedhold the axis moves to zero. I checked this in positive and negative directions. 
          The Z stops and resumes correctly in negative direction, and stops in the positive direction then runs to the negative limit on resume.
           X axis is the same as Y and goes to zero position when it resumes from a limitswitch feedhold stop.
          After shutting down the system and restarting a few times there is no telling if the limit switches will stop the axis.
          Some time the work on power up, sometimes you have to do the save,compile,download,run button for both threads.



          On Sunday, October 19, 2014 8:58 PM, "Tom Kerekes tk@... [DynoMotion]" <DynoMotion@yahoogroups.com> wrote:


           
          H Phil,

          That seems to reveal a bug in KFLOP resuming from feedhold.  Please try applying this patch:


          To apply this patch you must be using the latest Test Release V 4.33g


          Copy to the DSP_KFLOP Directory and Flash New Version

          Regarding the Feed Hold Indicator - I applaud you writing code!  But the the fuction GetStopState doesn't exist.  You should just be able to test CS0_StoppingState for non zero with:


          if  (CS0_StoppingState == 0);  // 0=no feed hold in progress
          {
              ClearBit(FEEDHOLD_IND);}
          else
          {
              ClearBit(FEEDHOLD_IND);
          }


          Regards
          TK


          From: "phil loder philloder@... [DynoMotion]" <DynoMotion@yahoogroups.com>
          To: "DynoMotion@yahoogroups.com" <DynoMotion@yahoogroups.com>
          Sent: Sunday, October 19, 2014 8:35 AM
          Subject: Re: [DynoMotion] PLC control of positions

           
          Tom,
          I tried the mods and My limits are back to working. 
          When I make a limit switch all motion stops and I have to toggle feedhold to resume. 
          When I turn on  the feedhold bit during a triggered move it stops all motion, If motion was stopped before it was complete on a axis the system seems to think that that axis has completed motion and will complete the next axis moves.   x is supposed to go to 20 and feedhold stops it at 10. upon clearing feedhold x stays at 10 instead of finishing its move then z makes its move thinking x,y are in position.Crash!

          I tried to modify the following to show the status of feed_Hold and it works if I toggle the input, but not if a limit switch is made.

          #define FEEDHOLD_IND 50

          void ServiceFeedhold(void)
          {
          int result;
          WaitNextTimeSlice();

          result = Debounce(ReadBit(FEED_HOLD),&t4count,&t4last,&t4lastsolid);

          // Handle FEED_HOLD Input
          if  (result == 1)
          {
          StopCoordinatedMotion();
          SetBit(FEEDHOLD_IND);
          }
          if (result == 0)
          {
          ResumeCoordinatedMotion();
          ClearBit(FEEDHOLD_IND);
          }
          }
          I thought removing my SetBit/ClearBit (FEED_HOLD) and adding the following would work, I was wrong!!! 
          But I am trying to do some on my own. What am I doing wrong in this code?

          // GET STOP STATE AND TURN ON/OFF INDICATOR "FEEDHOLD_IND"

          {
                  GetStopState();

          WaitNextTimeSlice();
          if  (CS0_StoppingState == 4);  // 4=independent motion of all related axes fully  stopped
          {
          SetBit(FEEDHOLD_IND);
          }
          if (CS0_StoppingState == 0);  //0 = not stopping
          {
          ClearBit(FEEDHOLD_IND);
          }
          }


          On Saturday, October 18, 2014 8:49 PM, "Tom Kerekes tk@... [DynoMotion]" <DynoMotion@yahoogroups.com> wrote:


           
          Hi Phil,

          I think I fixed two things.  Try the attached.

          Regards
          TK


          From: "philloder@... [DynoMotion]" <DynoMotion@yahoogroups.com>
          To: DynoMotion@yahoogroups.com
          Sent: Thursday, October 16, 2014 12:38 PM
          Subject: Re: [DynoMotion] PLC control of positions

           
          i just toggled the feedhold after motion started for step 2 input and it did a complete cycle of z to zero y to zero sent step2_complete. the PLC upon seeing that input sent a trigger_step1 and x went to the next row, y went to its last position and z went to -1.0 and then stopped and sent step1_complete.
          normally I would stop the PLC from sending a new position request when feedhold ==1 but tried this for raw c code testing.








          Group: DynoMotion Message: 10346 From: phil loder Date: 10/20/2014
          Subject: Re: PLC control of positions
          Tom,
          I also need help on my programming research. When using the console and clicking help, it shows GetStopState in the command list and I can use it in the console to verify my state of zero when all is normal and 4 when I use a limit to cause a feedhold condition.
          how do I know what is a usable command for programming? Is this the wrong list for programming commands?


          On Monday, October 20, 2014 10:32 AM, "phil loder philloder@... [DynoMotion]" <DynoMotion@yahoogroups.com> wrote:


           
          Tom,
          I flashed the update and included the new DSPKFLOP.out and saved the old one with a old extension.
          I reloaded my 2 threads and flashed them to user memory. verified the version in console as KFLOP 4.33h Build 18:42:16 Oct 19 2014
          when testing the stopping of a move with feedhold, it is stopping and continuing correctly when it is a commanded move.
          When I tested the limit switches they did not stop the axis. I had to do the save,compile,download,run and then it worked. Its weird due to the fact that the homing routine is in the same thread and ran fine. it also uses the near limit switched that I used for testing the feedhold on limits. Both thread 1,2 are checked to run on startup. 
          When the "Y" limit is made during a jog and it does stop, as soon as you toggle feedhold the axis moves to zero. I checked this in positive and negative directions. 
          The Z stops and resumes correctly in negative direction, and stops in the positive direction then runs to the negative limit on resume.
           X axis is the same as Y and goes to zero position when it resumes from a limitswitch feedhold stop.
          After shutting down the system and restarting a few times there is no telling if the limit switches will stop the axis.
          Some time the work on power up, sometimes you have to do the save,compile,download,run button for both threads.



          On Sunday, October 19, 2014 8:58 PM, "Tom Kerekes tk@... [DynoMotion]" <DynoMotion@yahoogroups.com> wrote:


           
          H Phil,

          That seems to reveal a bug in KFLOP resuming from feedhold.  Please try applying this patch:


          To apply this patch you must be using the latest Test Release V 4.33g


          Copy to the DSP_KFLOP Directory and Flash New Version

          Regarding the Feed Hold Indicator - I applaud you writing code!  But the the fuction GetStopState doesn't exist.  You should just be able to test CS0_StoppingState for non zero with:


          if  (CS0_StoppingState == 0);  // 0=no feed hold in progress
          {
              ClearBit(FEEDHOLD_IND);}
          else
          {
              ClearBit(FEEDHOLD_IND);
          }


          Regards
          TK


          From: "phil loder philloder@... [DynoMotion]" <DynoMotion@yahoogroups.com>
          To: "DynoMotion@yahoogroups.com" <DynoMotion@yahoogroups.com>
          Sent: Sunday, October 19, 2014 8:35 AM
          Subject: Re: [DynoMotion] PLC control of positions

           
          Tom,
          I tried the mods and My limits are back to working. 
          When I make a limit switch all motion stops and I have to toggle feedhold to resume. 
          When I turn on  the feedhold bit during a triggered move it stops all motion, If motion was stopped before it was complete on a axis the system seems to think that that axis has completed motion and will complete the next axis moves.   x is supposed to go to 20 and feedhold stops it at 10. upon clearing feedhold x stays at 10 instead of finishing its move then z makes its move thinking x,y are in position.Crash!

          I tried to modify the following to show the status of feed_Hold and it works if I toggle the input, but not if a limit switch is made.

          #define FEEDHOLD_IND 50

          void ServiceFeedhold(void)
          {
          int result;
          WaitNextTimeSlice();

          result = Debounce(ReadBit(FEED_HOLD),&t4count,&t4last,&t4lastsolid);

          // Handle FEED_HOLD Input
          if  (result == 1)
          {
          StopCoordinatedMotion();
          SetBit(FEEDHOLD_IND);
          }
          if (result == 0)
          {
          ResumeCoordinatedMotion();
          ClearBit(FEEDHOLD_IND);
          }
          }
          I thought removing my SetBit/ClearBit (FEED_HOLD) and adding the following would work, I was wrong!!! 
          But I am trying to do some on my own. What am I doing wrong in this code?

          // GET STOP STATE AND TURN ON/OFF INDICATOR "FEEDHOLD_IND"

          {
                  GetStopState();

          WaitNextTimeSlice();
          if  (CS0_StoppingState == 4);  // 4=independent motion of all related axes fully  stopped
          {
          SetBit(FEEDHOLD_IND);
          }
          if (CS0_StoppingState == 0);  //0 = not stopping
          {
          ClearBit(FEEDHOLD_IND);
          }
          }


          On Saturday, October 18, 2014 8:49 PM, "Tom Kerekes tk@... [DynoMotion]" <DynoMotion@yahoogroups.com> wrote:


           
          Hi Phil,

          I think I fixed two things.  Try the attached.

          Regards
          TK


          From: "philloder@... [DynoMotion]" <DynoMotion@yahoogroups.com>
          To: DynoMotion@yahoogroups.com
          Sent: Thursday, October 16, 2014 12:38 PM
          Subject: Re: [DynoMotion] PLC control of positions

           
          i just toggled the feedhold after motion started for step 2 input and it did a complete cycle of z to zero y to zero sent step2_complete. the PLC upon seeing that input sent a trigger_step1 and x went to the next row, y went to its last position and z went to -1.0 and then stopped and sent step1_complete.
          normally I would stop the PLC from sending a new position request when feedhold ==1 but tried this for raw c code testing.